import { fileURLToPath, URL } from "node:url";
import { defineConfig } from "vite";
import AutoImport from "unplugin-auto-import/vite";
import vue from "@vitejs/plugin-vue";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
export default defineConfig({
  plugins: [
    vue(),

    AutoImport({
      //将vue和vue-router作为全局导入
      imports: ["vue", "vue-router"],
      resolvers: [ElementPlusResolver()],
      dts: "./auto-imports.d.ts", //生成自动导入的声明文件
      dirs: ["src/composables/**.js", "src/composables/Api/**.js"],
      eslintrc: {
        enabled: true, //生成eslint配置文件规则
        filepath: "./.eslintrc-auto-import.json", //生成文件地址
      },
      // 运行至指定端口
    }),

    Components({
      dts: "./components.d.ts", //生成组件声明文件
      resolvers: [ElementPlusResolver()],
    }),
  ],
  server: {
    proxy: {
      "/api": {
        target: "http://localhost:3000", //产生跨域的地址
        changeOrigin: true,
      },
    },
  },
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
});
